package main;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.Vector;

import javax.swing.JPanel;

import datastructures.Datum;

/**
 * @author kf6kjg
 * 
 */
public class DisplayPanel extends JPanel {
  private static final long serialVersionUID = 1L;
  
  private Vector<Datum>     data;
  
    /**
   * @param data the data to set
   */
  public void setData(Vector<Datum> data) {
    this.data = data;
  }

  /**
   * 
   */
  public DisplayPanel() {
    this.setBackground(GlobalSettings.BackgroundColor);
  }
  
  /**
   * 
   */
  public DisplayPanel(Vector<Datum> data) {
    this();
    this.setData(data);
  }
  
  /*
   * (non-Javadoc)
   * 
   * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
   */
  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    
    if (data == null) return;
    
    Graphics2D g2d = (Graphics2D) g;
    
    float step = (float) this.getWidth() / (float) (data.size() + 1);
    
    float x_pos = step - 1;
    
    for (Datum datum : this.data) {
      g2d.setColor(datum.getColor());
      
      g2d.fillRect((int) x_pos, (this.getHeight() * (GlobalSettings.VertDetail - datum.value)) / GlobalSettings.VertDetail, GlobalSettings.LineWidth, this.getHeight());
      
      x_pos += step;
    }
  }
  
}
